<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ include file="/taglibs.jsp"%>
<html>
<head>
<title>IT管理后台</title>
<link rel="stylesheet" type="text/css" href="/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/themes/icon.css">
<script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/easyui_validatebox.js"></script>
<script type="text/javascript" src="/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/js/util.js"></script>
<script src="/js/print.js" type="text/javascript"></script>
<style type="text/css">
td {
	font-size: 13px
}
#kctj-add td{
	text-align: right;
}
#kctj-edit td{
	text-align: right;
}
.tjclass{
	background-image: url("/images/score.gif");
    background-position: left center;
    background-repeat: no-repeat;
    padding-left: 15px;
    color: red;
}
</style>
	<script>
		$(function(){
			$('#tab').datagrid({
				title:'库存统计',
				iconCls:'icon-save',
				nowrap: false,
				striped: true,
				pageSize:20,
				sortName:"id",
				sortOrder:"desc",
				pageList:[10,20,30,40,50],
				url:'/itmanager/kctj/json',
				remoteSort: false,
				idField:'id',
				frozenColumns:[[
	                	{field:'ck',checkbox:true},
	                	{title:'进货时间',field:"jhsj",width:80,formatter:
							function(value,rowDate,rowIndex){
							return "<font color='blue'>"+value+"</font>";
							}
	                	},
						{title:'负责人',field:"fzr",width:80},
						{title:'物品种类',field:"wpzl",width:80},
						{title:'物品名称',field:"wpmc",width:120},
						{title:'物品数量',field:"wpsl",width:60,formatter:
							function(value,rowDate,rowIndex){
								return "<font color='red'>"+value+"</font>";
							}
						},
						{title:'计量单位',field:"jldw",width:60}
	                ]],
				columns:[
					[
						{title:"备注",field:"bz",width:120}
					]
				],
				fit:true,
				fitColumns:true,
				border:false,
				pagination:true,
				rownumbers:true,
				toolbar:[{
					id:'1',
					text:'添加',
					disabled:true,
					iconCls:'icon-add',
					handler:function(){
						kctjadd.window({
							onBeforeOpen:function(){
								kctjaddform.form('clear');
								$("#jhsj-add").datebox("setValue",textDate());
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=wp",
									   success: function(msg){
										   var bmm = $("#wpzlid-add")[0];  //把jquery对象转成dom对象使用
										   clearSel(bmm); //清空
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												bmm.options.add(option);
											});
									   }
									});
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=jldw",
									   success: function(msg){
										   var zww = $("#jldwid-add")[0];  //把jquery对象转成dom对象使用
										   clearSel(zww); //清空
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												zww.options.add(option);
											});
									   }
									});
							}
						});
						kctjadd.window("open");
					}
				},'-',{
					id:'2',
					text:'修改',
					disabled:true,
					iconCls:'icon-edit',
					handler:function(){
						kctjedit.window({
							onBeforeOpen:function(){
								kctjeditform.form('clear');
								var rows = $("#tab").datagrid("getSelections");
								var length = rows.length;
								if(length != 1){
									$.messager.alert("友情提示","<br/><b>只能选择一条记录！</b>","error");
									return false;
								}
								var id=rows[0].id;
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=wp",
									   success: function(msg){
										   var bmm = $("#wpzlid-edit")[0];  //把jquery对象转成dom对象使用
										   clearSel(bmm); //清空
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												bmm.options.add(option);
											});
									   }
									});
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=jldw",
									   success: function(msg){
										   var zww = $("#jldwid-edit")[0];  //把jquery对象转成dom对象使用
										   clearSel(zww); //清空
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												zww.options.add(option);
											});
									   }
									});
								$.ajax({
							 		type:"get",
							 		url:"/itmanager/kctj/show",
							 		data:"id="+id,
							 		cache:false,
							 		success:function(data){
							 		 	data=$.parseJSON(data);
										$("#jhsj-edit").datebox("setValue",data.jhsj);
										$("#fzr-edit").val(data.fzr);
										$("#wpmc-edit").val(data.wpmc);
										$("#wpzlid-edit").val(data.wpzlid);
										$("#wpsl-edit").val(data.wpsl);
										$("#jldwid-edit").val(data.jldwid);
										$("#bz-edit").val(data.bz);
							 		}
							 	});
							}
						});
						kctjedit.window("open");
					}
				},'-',{
					id:'3',
					text:'删除',
					disabled:true,
					iconCls:'icon-remove',
					handler:function(){
						deleteKctj();
					}
				},'-',{
					id:'10',
					text:'查看统计',
					disabled:true,
					iconCls:'icon-search',
					handler:function(){
						tj();
					}
				},'-',{
					id:'9',
					text:'打印',
					disabled:true,
					iconCls:'icon-print',
					handler:function(){
						startPrint($(".datagrid-view")[0]);
					}
				}]
			});
			
			 $("#tab").datagrid("getPager").pagination({
				   onSelectPage:function(){
					  $("#tab").datagrid("clearSelections");
					  var queryParams = $.extend({},$("#tab").datagrid("options").queryParams,
							  {spfzr:$("#fzr-search").val(),spwp:$("#wp-search").val(),spbfjlsj:$("#bfjlsj-search").datebox("getValue"),spafjlsj:$("#afjlsj-search").datebox("getValue")});  
					  $("#tab").datagrid("reload",queryParams);
				   }
			  });
			kctj = $('#kctj-window').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			kctjadd = $('#kctj-add').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			kctjaddform=kctjadd.find("form");
			kctjedit = $('#kctj-edit').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			kctjedit.window({
				onBeforeClose:function(){
					var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
		 			$("#tab").datagrid("reload",queryParams);
				}
			});
			kctjeditform=kctjedit.find("form");
			
			 var ens='${param.en}';
			 var en=ens.split(":");
			 for(var i=0;i<en.length;i++){
				 if(en[i] != "" && en[i] != null){
				 	$("#"+en[i]).linkbutton('enable');
				 }
			 }
			
		});
		
		var find = function(){
			$("#tab").datagrid("clearSelections");
			var queryParams = $.extend({},$("#tab").datagrid("options").queryParams,
					{spfzr:$("#fzr-search").val(),spwpzlid:$("#wpzlid-search").val(),spbfjlsj:$("#bfjlsj-search").datebox("getValue"),spafjlsj:$("#afjlsj-search").datebox("getValue")}); 
			$("#tab").datagrid("getPager").pagination({pageNumber:1});
			$("#tab").datagrid("reload",queryParams);
		}
		
		var tj=function(){
			$("#tj-msg").html("");
			$.ajax({
		 		type:"get",
		 		url:"/itmanager/kctj/tj",
		 		cache: false,
		 		success:function(data){
		 		 	kctj.window("open");
		 		 	data=$.parseJSON(data);
					var sign=" •  •  •  •  •  •  •  •  • ";
					$.each(data,function(i,ob){
						$("#tj-msg").append("<li>"+ob.wpzl+sign+"<span class='tjclass'>"+ob.zsl+"</span>"+ob.jldw+"</li>");
					});
		 		}
		 	});
		}
		
		function mtext(target,text){
			$(target).html("&nbsp;");
			$(target).html(text);
		}
		
		function clearSel(oSelect) {
			while (oSelect.childNodes.length > 0) {
				oSelect.removeChild(oSelect.childNodes[0]);
			}
		}
		
		function closeKctjadd(){
			kctjadd.window('close');
		}
		function closeKctjedit(){
			kctjedit.window('close');
		}
		
		function createKctj(){
			kctjaddform.form('submit', {  
				  url:kctjaddform.action,
				  onSubmit:function(){
				        return $(this).form('validate');
				    },
				  success:function(data){
				          if (data=='success'){  
				        	  	$.messager.alert('信息提示','添加成功！','right');  
				                kctjadd.window('close');  
				                var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
					 			$("#tab").datagrid("reload",queryParams);
				            } else if(data=='error'){
				            	$.messager.alert('信息提示','添加失败！','error');
				            }
				     }  
			});  
		}
		
		function editKctj(){
			var rows = $("#tab").datagrid("getSelections");
			var length = rows.length;
			if(length != 1){
				$.messager.alert("友情提示","<br/><b>只能选择一条记录！</b>","error");
				return false;
			}
			var id=rows[0].id;
			kctjeditform.form('submit', {  
				  url:"/itmanager/kctj/edit?id="+id,
				  onSubmit:function(){
				        return $(this).form('validate');
				    },
				  success:function(data){
				          if (data=='success'){  
				        	  	$.messager.alert('信息提示','修改成功！','right');  
				                
				            } else if(data=='error'){
				            	$.messager.alert('信息提示','修改失败！','error');
				            }
				     }  
			});  
		}
		
		var deleteKctj = function(){
			var rows = $("#tab").datagrid("getSelections");
			var length = rows.length;
			if(length == 0){
				$.messager.alert("友情提示","<br/><b>请先选择记录！</b>","error");
				return false;
			}
			var ids = [];
			for(var i=0;i<length;i++){
				ids.push(rows[i].id);
			}
			ids.join(",");
			$.messager.confirm("友情提示","<br/><b>确定删除记录？</b>",function(result){
				if(result){
					$.ajax({
				 		type:"post",
				 		url:"/itmanager/kctj/delete",
				 		data:"ids="+ids,
				 		success:function(data){
				 			if(data=='success'){
				 		 		var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
				 				$("#tab").datagrid("reload",queryParams);
				 				$("#tab").datagrid("clearSelections");
				 			}else if(data=='error'){
				 				$.messager.alert("友情提示","<br/><b>删除记录出错！</b>","error");
				 			}
				 		}
				 	});
				}
			});
		} 
		
	</script>
</head>
<body class="easyui-layout">
	<div region="north" border="false" style="height:80px;" iconCls="icon-search" title="查询条件">
		<table width="100%" height="100%" style="background-color:#E0ECFF ">
			<thead>
				<tr>
					<td align="center">负责人：</td>
					<td><input type="text" name="spfzr" id="fzr-search" value="${smap.spfzr }"></td>
					<td align="center">物品种类：</td>
					<td>
						<select name="spwpzlid" id="wpzlid-search">
							<option value="">--请选择--</option>
							<c:forEach items="${wp }" var="b">
								<option value="${b.id }" <c:if test="${smap.spwpzlid==b.id }">selected</c:if>>${b.clmc }</option>
							</c:forEach>
						</select>
					</td>
					<td align="center">查询时间：</td>
					<td nowrap="nowrap">
						<input name="spbfjlsj" id="bfjlsj-search" class="easyui-datebox"/>到<input name="spafjlsj" id="afjlsj-search" class="easyui-datebox"/>
					</td>
					<td><a id="4" disabled="true" class="easyui-linkbutton" iconCls="icon-search" onclick="find()">查询</a></td>
				</tr>
			</thead>
		</table>
	</div>
	<div id="center" region="center">
		<table id="tab"></table>
	</div>
	
	<div id="kctj-window" title="查看库存统计" style="width:280px;">
		<ul id="tj-msg" style="padding-top: 15px;font-size: 15px;font-weight:bolder;"></ul>
	</div>
	
	<div id="kctj-add" title="添加库存" style="width:350px;height:350px;">
				<div style="text-align: center;padding-top: 5px;">
					<form method="post" action="/itmanager/kctj/add">
						<table>
							<tr>
								<td>进货时间：</td>
								<td><input name="jhsj" id="jhsj-add" type="text" class="easyui-datebox" required="true" style="width:150px;"></input></td>
							</tr>
							<tr>
								<td>负责人：</td>
								<td>
									<input type="text" name="fzr" id="fzr-add" class="easyui-validatebox" required="true">
								</td>
							</tr>
							<tr>
								<td>物品种类：</td>
								<td>
									<select name="wpzlid" id="wpzlid-add" style="width:150px;">
									</select>
								</td>
							</tr>
							<tr>
								<td>物品名称：</td>
								<td>
									<input type="text" name="wpmc" id="wpmc-add" class="easyui-validatebox" required="true">
								</td>
							</tr>
							<tr>
								<td>数量：</td>
								<td>
									<input type="text" name="wpsl" id="wpsl-add" class="easyui-numberbox" required="true">
								</td>
							</tr>
							<tr>
								<td>计量单位：</td>
								<td><select name="jldwid" id="jldwid-add" style="width:150px;">
									</select></td>
							</tr>
							<tr>
								<td>备注：</td>
								<td>
									<textarea name="bz" style="width:150px;height:50px;"></textarea>
								</td>
							</tr>
						</table>
					</form>
				</div>
				<div style="text-align:center;">
					<a href="javascript:void(0)" onclick="createKctj()" class="easyui-linkbutton" id="kctj-add-button" icon="icon-save">添加</a>
					<a href="javascript:void(0)" onclick="closeKctjadd()" class="easyui-linkbutton" id="kctj-cancel-button" icon="icon-cancel">取消</a>
				</div>
		</div>
		
		<div id="kctj-edit" title="修改员工信息" style="width:350px;height:350px;">
				<div style="text-align: center;padding-top: 5px;">
					<form method="post" action="/itmanager/kctj/edit">
						<table>
							<tr>
								<td>进货时间：</td>
								<td><input name="jhsj" id="jhsj-edit" type="text" class="easyui-datebox" required="true" style="width:150px;"></input></td>
							</tr>
							<tr>
								<td>负责人：</td>
								<td>
									<input type="text" name="fzr" id="fzr-edit" class="easyui-validatebox" required="true">
								</td>
							</tr>
							<tr>
								<td>物品种类：</td>
								<td>
									<select name="wpzlid" id="wpzlid-edit" style="width:150px;">
									</select>
								</td>
							</tr>
							<tr>
								<td>物品名称：</td>
								<td>
									<input type="text" name="wpmc" id="wpmc-edit" class="easyui-validatebox" required="true">
								</td>
							</tr>
							<tr>
								<td>数量：</td>
								<td>
									<input type="text" name="wpsl" id="wpsl-edit" class="easyui-numberbox" required="true">
								</td>
							</tr>
							<tr>
								<td>计量单位：</td>
								<td><select name="jldwid" id="jldwid-edit" style="width:150px;">
									</select></td>
							</tr>
							<tr>
								<td>备注：</td>
								<td>
									<textarea name="bz" id="bz-edit" style="width:150px;height:50px;"></textarea>
								</td>
							</tr>
						</table>
					</form>
				</div>
				<div style="text-align:center;">
					<a href="javascript:void(0)" onclick="editKctj()" class="easyui-linkbutton" id="kctj-edit-button" icon="icon-ok">修改</a>
					<a href="javascript:void(0)" onclick="closeKctjedit()" class="easyui-linkbutton" id="kctj-cancel-button" icon="icon-cancel">取消</a>
				</div>
		</div>

</body>
</html>